#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define mm0(a) memset(a, 0, sizeof(a))
#define mmf1(a) memset(a, -1, sizeof(a))
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int N  = 1e4 + 10, M = 2 * N;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}


int n;
int e[M], ne[M], h[N], idx;
int p[N];

int find(int x) {
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}

void add(int a, int b) {
    e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}

int dfs(int u, int father) {
    int depth = 0;
    for (int i = h[u]; i != -1; i = ne[i]) {
        int j = e[i];
        if (j == father) continue;
        depth = max(depth, dfs(j, u) + 1);
    }
    return depth;
}

inline void solution() {
    cin >> n;
    int cnt = n;

    mmf1(h);
    rep(i, 1, n) p[i] = i;

    for (int i = 0; i < n; i ++ ) {
        int a, b;
        cin >> a >> b;
        if (find(a) != find(b)) {
            cnt --;
            p[find(a)] = find(b);
        }
        add(a, b), add(b, a);
    }
    if (cnt > 1) printf("Error: %d components\n", cnt);
    else {
        int max_depth = -1;
        vector<int> nodes;
        for (int i = 1; i <= n; i ++ ) {
            int depth = dfs(i, -1);
            if (depth > max_depth) {
                max_depth = depth;
                nodes.clear();
                nodes.push_back(i);
            } else if (depth == max_depth)
                nodes.push_back(i);
        }

        for (auto & node : nodes) cout << node << endl;
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}